//
//  init.cpp
//  
//
//  Created by Nikita Luzyanin on 30.11.13.
//
//

#include <iostream>
#include <fstream>
#include <iomanip>
#include <stdlib.h>
using namespace std;

void createEmptyBlocks(int sizeOfBlock, int amountOfBlocks, char *pathToFS)
{
    ofstream F;
    strcat(pathToFS, "/");
    char pathToFile[100];
    for (int i = 0; i < amountOfBlocks; i++) {
        char number[15];
        sprintf(number, "%i", i);
        strcpy(pathToFile, pathToFS);
        strcat(pathToFile, number);
        
        F.open(pathToFile);
        for (int j = 0; j < sizeOfBlock; j++) {
            F << 0;
        }
        F.close();
    }
}

int main(int argc, char* argv[])
{
    ifstream config;
    int sizeOfBlock, amountOfBlocks;
    char *pathToFS;
    
    config.open("config");
    config >> sizeOfBlock;
    config >> amountOfBlocks;
    config.close();
    if (sizeOfBlock * amountOfBlocks > 50 * 1024 * 1024) {
        cout << "Size of file system is too big\n";
        return 1;
    }
    cout << amountOfBlocks << "\n";
    cout << sizeOfBlock << "\n";
    if (sizeOfBlock < 1024) {
        cout << "Size of block is too small\n";
        return 1;
    }
    pathToFS = argv[1];
    if (!fopen(pathToFS, "rb")) {
        cout << "Path to FS does not exist\n";
        return 1;
    }
    
    createEmptyBlocks(sizeOfBlock, amountOfBlocks, pathToFS);
    
    return 0;
}